<template>
  <div>
    <f-search-form :more='true' @searchHandler='searchHandler'>
      <f-search-form-item label='部门' ref='dept' name='deptId' type='select' :data='this.api.hyorder.listByCompanyId' valueKey='deptId' label-key='deptName' />
      <f-search-form-item label='单位名称' name='customName' />
      <f-search-form-item label='认款单号' name='paymentNo' />
      <f-search-form-item label='收款日期' type='range' name='beginDate' slot='advanced' />
      <f-search-form-item label='创建日期' type='range' :rangeConfig='rangeConfig' name='createTime' slot='advanced' />
    </f-search-form>
    <f-table ref='table' size='small' 
             rowKey='paymentId' 
             :columns='columns' 
             :scroll='scroll' 
             :multiple='false' 
             :operator='operator' 
             :params='queryParam' 
             :api='api.payment'
             handler='hyAskAmountTaskTab3Handler'>
       <span slot='amountType' slot-scope='text, record, index'>
         <a-tag color='#b2d235' v-if="text=='CustomRefund'">客户回款</a-tag>
         <a-tag color='#6B8E23' v-if="text=='CustomBond'">资保金收款</a-tag>
         <a-tag color='#6B8E23' v-if="text=='YfkAmount'">预收款收款</a-tag>
         <a-tag color='#108ee9' v-if="text=='OrderAmount'">现款</a-tag>
         <a-tag color='#87d068' v-if="text=='DepositAmount'">保证金</a-tag>
      </span>
      <span slot='deptType' slot-scope='text'>
        <a-tag color='#2db7f5' v-if='text=="ZS"'>招商</a-tag>
        <a-tag v-if='text=="ZY"'>自营</a-tag>
      </span>
      <span slot='hkImage' slot-scope='text, record, index'>
        <f-images :value='record.hkImage'></f-images>
      </span>
      <span slot='action' slot-scope='text, record'>
<!--          <template>
              <a href='javascript:;' @click="$refs['returnDetailsDrawer'].showDrawer(record)">明细</a>
              <a-divider type='vertical' />
          </template>-->
           <a @click='openPaymentOrderModal(record)' v-if='record.amount>record.surplusAmount'>认款明细</a>
            <a-divider type='vertical' v-if='record.amount>record.surplusAmount'></a-divider>
           <a-dropdown>
              <a class='ant-dropdown-link'>更多 <a-icon type='down' /></a>
              <a-menu slot='overlay'>
                <a-menu-item>
                  <a href='javascript:;' @click='processImg(record)'>审批进度</a>
                </a-menu-item>
                <!--                <a-menu-item>
                                  <a href="javascript:;" @click="deleteProcessInstance(record.processInstanceId)">删除流程实例</a>
                                </a-menu-item>-->
                <a-menu-item v-if='superAdmin'>
                 <a href='javascript:;' @click='deleteProcessInstance(record.processInstanceId,"hyYfkProcDeleteHandler")'>撤销审批</a>
                </a-menu-item>
                <a-menu-item v-if='record.amountType=="CustomRefund"'>
                  <a href='javascript:;' @click='printPayment2(record.paymentId)'>查看认款单</a>
                </a-menu-item>
                 <a-menu-item v-if='record.amountType=="CustomRefund"'>
                   <a @click='$refs.returnDetailsDrawer.showDrawer(record)' v-if='record.amountType=="CustomRefund"'>发货明细</a>
                </a-menu-item>
                 <a-menu-item v-if='record.amountType!="CustomRefund"'>
                  <a href='javascript:;' @click='printPayment(record.paymentId)'>查看认款单</a>
                </a-menu-item>
              </a-menu>
            </a-dropdown>
        </span>
    </f-table>
    <process-image ref='processImg' v-if='processImageVisible' :visible.sync='processImageVisible' :processInstanceId='processInstanceId'></process-image>
    <return-details-drawer ref='returnDetailsDrawer'></return-details-drawer>
    <print-modal ref='printModal' :showPrint='false'></print-modal>
    <select-payment-order-modal ref='paymentOrderModal'></select-payment-order-modal>
  </div>
</template>
<script>

import api from "../../js/api"
import ProcessImage from "../../../flowable/process/process_image"
import ReturnDetailsDrawer from "@/views/module/haiying/order/return/components/return_details_drawer"
import { processMixins } from "@/core/mixins/processMixins"
import PrintModal from "../../print/print_modal"
import SelectPaymentOrderModal from "@/views/module/haiying/components/select_payment_order_modal"
import Vue from "vue"

export default {
  name: "Tab3",
  components: {
    SelectPaymentOrderModal,
    ReturnDetailsDrawer,
    ProcessImage,
    PrintModal
  },
  mixins: [processMixins],
  data() {
    let me = this
    //操作按钮
    let operator = []
    let companyList = Vue.ls.get("companyList")
    return {
      api: Object.assign(api, this.api),
      //列表初始化查询参数
      queryParam: {},
      scroll: { x: true },
      rangeConfig: {
        beginName: "createBeginDate",
        endName: "createEndDate"
      },
      processInstanceId: "",
      processImageVisible: false,
      // 表头
      columns: [
        {
          title: "序号",
          width: "50px",
          align: "center",
          fixed: "left",
          customRender: (text, record, index) => index + 1
        },
        {
          title: "认款单号",
          align: "center",
          fixed: "left",
          dataIndex: "paymentNo"
        },
        {
          title: "单据类型",
          align: "left",
          width: "100px",
          dataIndex: "amountType",
          scopedSlots: { customRender: "amountType" },
          filters: [
            {
              text: "回款认款",
              value: "CustomRefund"
            },
            {
              text: "资保金认款",
              value: "CustomBond"
            },
            {
              text: "预收款",
              value: "YfkAmount"
            },
            {
              text: "保证金",
              value: "DepositAmount"
            }
          ],
          filterMultiple: false
        },
        {
          title: "部门名称",
          align: "left",
          width: "150px",
          dataIndex: "deptName"
        },
        {
          title: "业务员",
          align: "left",
          width: "90px",
          ellipsis: true,
          dataIndex: "saleManName"
        },
        {
          title: "业务编码",
          align: "left",
          width: "120px",
          dataIndex: "businessCode"
        },
        {
          title: "回款单位",
          align: "left",
          width: "100px",
          ellipsis: true,
          dataIndex: "payUserName"
        },
        {
          title: "回款金额",
          align: "left",
          width: "80px",
          dataIndex: "amount"
        },
        {
          title: "回款日期",
          align: "left",
          width: "100px",
          dataIndex: "amountDate"
        },
        {
          title: "收款银行",
          align: "left",
          width: "120px",
          dataIndex: "bankName"
        },
        {
          title: "付款账户",
          align: "left",
          width: "100px",
          ellipsis: true,
          dataIndex: "payBankNo"
        },
        {
          title: "制单人",
          align: "left",
          width: "80px",
          dataIndex: "nickName"
        },
        {
          title: "创建日期",
          align: "left",
          dataIndex: "createTime"
        },
        {
          title: "备注",
          align: "left",
          dataIndex: "remark",
          width: "100px"
        },
        {
          title: "剩余金额",
          align: "left",
          width: "80px",
          fixed: "right",
          dataIndex: "surplusAmount"
        },
        {
          title: "操作",
          align: "center",
          dataIndex: "action",
          width: "135px",
          fixed: "right",
          scopedSlots: { customRender: "action" }
        }
      ],
      operator: operator
    }
  },
  created() {
  },
  methods: {
    onLoad() {
      this.$refs.table.refresh()
    },

    processImg(task) {
      this.processInstanceId = task.processInstanceId
      this.processImageVisible = true
    },
    /**
     * 查询事件
     * @param searchParams
     */
    searchTable(searchParams) {
      this.queryParam = Object.assign(this.queryParam, searchParams)
      this.$refs.table.refresh(true, searchParams)
    },
    //打开认款使用明细
    openPaymentOrderModal(record) {
      this.$refs.paymentOrderModal.open({
        paymentId: record.paymentId,
        amount: record.amount
      })
    },
    //打印单
    printPayment(paymentId) {
      this.$refs["printModal"].open(paymentId, 4, "YfkAmount")
    },
    //打印单
    printPayment2(paymentId) {
      this.$refs["printModal"].open(paymentId, 6, "CustomRefund")
    }
  }
}
</script>
